package Leetcode;

import java.util.Arrays;
import java.util.Comparator;

public class problem435 {

    static class Interval {

        int start;

        int end;

        Interval() { start = 0; end = 0; }

        Interval(int s, int e) { start = s; end = e; }
    }

    public static int eraseOverlapIntervals(Interval[] intervals) {
        Arrays.sort(intervals, new Comparator<Interval>() {
            @Override
            public int compare(Interval t1, Interval t2) {
                return t1.end - t2.end;
            }
        });

        int end = Integer.MIN_VALUE;
        int count = 0;

        for (int i = 0; i < intervals.length; i++) {
            if(intervals[i].start < end){
                continue;
            }
            end = intervals[i].end;
            count++;
        }


        return intervals.length - count;
    }

    public static void main(String[] args) {
        Interval interval = new Interval(1,2);
        Interval[] intervals = new Interval[]{interval};
        eraseOverlapIntervals(intervals);
    }
}
